package cn.iocoder.yudao.module.pi.dal.mysql.task;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pi.controller.admin.pipline.task.vo.StageTaskReqVO;
import cn.iocoder.yudao.module.pi.controller.admin.pipline.task.vo.TaskPageReqVO;
import cn.iocoder.yudao.module.pi.dal.dataobject.task.TaskDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 流水线阶段任务 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface TaskMapper extends BaseMapperX<TaskDO> {

    default PageResult<TaskDO> selectPage(TaskPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getRegion, reqVO.getRegion())
                .eqIfPresent(TaskDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(TaskDO::getEnv, reqVO.getEnv())
                .eqIfPresent(TaskDO::getPiplineId, reqVO.getPiplineId())
                .likeIfPresent(TaskDO::getPiplineName, reqVO.getPiplineName())
                .eqIfPresent(TaskDO::getStageCiId, reqVO.getStageCiId())
                .likeIfPresent(TaskDO::getStageCiName, reqVO.getStageCiName())
                .eqIfPresent(TaskDO::getTaskCiId, reqVO.getTaskCiId())
                .likeIfPresent(TaskDO::getTaskCiName, reqVO.getTaskCiName())
                .betweenIfPresent(TaskDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TaskDO::getId));
    }

    default List<TaskDO> getStageTask(StageTaskReqVO reqVO){
        return selectList(new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getRegion, reqVO.getRegion())
                .eqIfPresent(TaskDO::getProjectId, reqVO.getProjectId())
                .eqIfPresent(TaskDO::getEnv, reqVO.getEnv())
                .orderByDesc(TaskDO::getId));
    }

    default List<TaskDO> getTaskList(String env){
        return selectList(new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getEnv, env)
                .orderByDesc(TaskDO::getId));
    }
}